package com.proposition.support.security;

import com.proposition.commons.model.User;
import com.proposition.support.exception.LogOutException;
import org.apache.shiro.SecurityUtils;

/**
 * @author 杨凯
 */

public enum CurrentUser {

	INSTANCE;
	
	/**
	 * 获取当前用户Id
	 * @return
	 */
	public String getUserId(){
		User user = (User) SecurityUtils.getSubject().getPrincipal();
		if(null == user){
			 throw new LogOutException("当前用户未登录");
		}
		return user.getId();
	}
	
	/**
	 * 获取当前用户姓名
	 * @return
	 */
	public String getUserName(){
		User user = (User) SecurityUtils.getSubject().getPrincipal();
		if(null == user){
			 throw new LogOutException("当前用户未登录");
		}
		return user.getRealName();
	}
	/**
	 * 获取当前用户
	 * @return
	 */
	public User getUser(){
		User user = (User) SecurityUtils.getSubject().getPrincipal();
		if(null == user){
			 throw new LogOutException("当前用户未登录");
		}
		return user;
	}
	
}
